*******NEONATAL SEPSIS***********
cd "C:\Users\user\Documents\MPH\manuscript"
log using sepsis.log, replace
insheet using "kahawa_hygiene_data.csv", clear names
dir
browse
****giving label variables*****
label variable serno "form serial number"
label variable participan "case vs control"
label variable neonage "neonate's age"
label variable neonsex "neonate's sex"
label variable matage "mother's age"
label variable marital "marital status"
label variable educ "level of education"
label variable religion "mother's religion"
label variable parity "parity status"
label variable substance "substance application"
label variable place "place of delivery"
label variable cordexp "cord exposure"
label variable handwash "hand washing"
label variable washing "washing substance"
label variable rooming "sleep in same room"
label variable bathing "spongebathing vs immersion"
label variable cry "cry at birth"
label variable resusc "resuscitation"
label variable line "intravenous line"
label variable amnio "amniotic fluid meconium"
label variable feeds "type of feed"
label variable delivtype "type of delivery"
label variable initiation "initiation of breastfeeding"
label variable anc "number of ANC visits"
label variable uti "urinary tract infection"
label variable immunizati "tetanus toxoid immunization"
label variable healtheduc "received health eduaction"
label variable source "source of health education"
label variable prom "premature rupture of membranes"
label variable complic "pregnancy complications"
label variable exactcompl "exact complication"
label variable children "number of children"
label variable score5 "apgar score at 5 min"
******identifying the string variables***********
rename participan participant_s
rename neonsex neonsex_s
rename marital marital_s
rename educ educ_s
rename religion religion_s
rename parity parity_s
rename substance substance_s
rename deliveryplace deliveryplace_s
rename cordexp cordexp_s
rename handwash handwash_s
rename washing washing_s
rename rooming rooming_s
rename bathing bathing_s
rename cry cry_s
rename resusc resusc_s
rename line line_s
rename amnio amnio_s
rename feeds feed_s
rename delivtype delivtype_s
rename initiation initiation_s
rename anc anc_s
rename uti uti_s
rename immunizati immunize_s
rename healtheduc healtheduc_s
rename source source_s
rename prom prom_s
rename complic complic_s

****encoding value labels from string variable*******
encode  participant_s, generate(participant)
tab participant
label define participantlabel 1 Control 2 Case
drop participant
encode  participant_s, generate(participant) label (participantlabel)
tab participant

tab participant
recode participant (1=0) (2=1), gen (sepsis)
label define sepsislabel 0 Control 1 Case
drop sepsis
recode participant (1=0) (2=1), gen (sepsis) label (sepsislabel)
label variable sepsis "RECODE of participant (control vs case)"
tab sepsis
codebook sepsis

tab neonsex_s
encode neonsex_s, gen(neonsex)
label define neonsexlabel 1 Male 2 Female
drop neonsex
encode neonsex_s, gen(neonsex) label(neonsexlabel)
tab neonsex

tab marital_s
encode marital_s, gen(marital1)
label define marital1label 1 Single 2 Married 3 Separated 4 Divorced
drop marital1
encode marital_s, gen(marital1) label(marital1label)
tab marital1
recode marital1 (1=1) (2=2) (3 4=3), gen(marital)
label define maritallabel 1 Single 2 Married 3 "Separated/divorced"
drop marital
recode marital1 (1=1) (2=2) (3 4=3), gen(marital) label(maritallabel)
tab marital

tab educ_s
encode educ_s, gen(educ)
label define educlabel 1 "No formal schooling" 2 Primary 3 Secondary 4 "College/University"
drop educ
encode  educ_s, gen(educ) label(educlabel)
tab educ

tab religion_s
encode religion_s, gen(religions)
label define religionslabel 1 "Protestant" 2 Catholic 3 Orthodox 4 Muslim 5 Pagan
drop religions
encode religion_s, gen(religions) label(religionslabel)
tab religions
recode religions (1=1) (2 3=2) (4 5=3), gen(religion)
label define religionlabel 1 Protestant 2 "Catholic/Orthodox" 3 "Other"
drop religion
recode religions (1=1) (2 3=2) (4 5=3), gen(religion) label(religionlabel)
tab religion


tab substance_s
encode substance_s, gen(substance1)
label define substance1label 1 "Ash" 2 Saliva 3 Water 4 None 5 "Silver sulphadiazine" 6 "Topical antibiotic" 7 Chlorhexidine 8 "Surgical spirit"
drop substance1
encode substance_s, gen(substance1) label(substance1label)
tab substance1
recode substance1 (1 2=0) (3 4=1) (5 6=2) (7 8=3), gen(substance)
label define substancelabel 1 "Ash" 2 Saliva 3 Water 4 None 5 "Silver sulphadiazine" 6 "Topical antibiotic" 7 Chlorhexidine 8 "Surgical spirit"
drop substance
recode substance1 (1 2=0) (3 4=1) (5 6=2) (7 8=3), gen(substance) label(substancelabel)
tab substance

tab deliveryplace_s
encode deliveryplace_s, gen(deliveryplace)
label define deliverylabel 0 Home 1 "Primary public" 2 "Public hospital" 3 "Private hospital"
drop deliveryplace
encode deliveryplace_s, gen(deliveryplace) label (deliverylabel)
tab deliveryplace

tab cordexp_s
encode cordexp_s, gen(cordexp)
label define cordexplabel 0 "Above cord" 1 "Below cord"
drop cordexp
encode cordexp_s, gen(cordexp)label (cordexplabel)
tab cordexp
codebook cordexp
tab sepsis cordexp, row


tab handwash_s
encode handwash_s, gen(handwash)
label define handwashlabel 0 "No" 1 "Yes"
drop handwash
encode handwash_s, gen(handwash)label (handwashlabel)
tab handwash
codebook handwash
tab sepsis handwash, row

tab washing_s
encode washing_s, gen(washuse)
label define washuselabel 0 "None" 1 "Water only" 2 "Water and soap" 
drop washuse
encode washing_s, gen(washuse) label(washuselabel)
tab washuse
codebook washuse
tab sepsis washuse, row

tab rooming_s
encode rooming_s, gen(rooming)
label define roominglabel 0 "No" 1 "Yes"
drop rooming
encode rooming_s, gen(rooming)label (roominglabel)
tab rooming
codebook rooming
tab rooming
tab sepsis rooming, row

tab bathing_s
encode bathing_s, gen(bathing)

tab sepsis bathing, row

tab cry_s
encode cry_s, gen(cry)
label define crylabel 0 "No" 1 "Yes"
drop cry
encode cry_s, gen(cry) label(crylabel)
tab cry

tab resusc_s
encode resusc_s, gen(resusc)
tab resusc

tab line_s
encode line_s, gen(line)
tab line

******generating invasive from resc and line***
generate score_invasive = resusc+line
recode score_invasive (min/2=0) (3/max=1), gen (invasive)
label define invasivelabel 0 "No invasive procedure" 1 "Invasive procedure"
drop invasive
recode score_invasive (min/2=0) (3/max=1), gen(invasive) label(invasivelabel)
label variable invasive "Invasive procedures"
tab invasive
******generating apgar score***
recode score5 (min/7=2) (8/max=1), gen (apgar)
label define apgarlabel 1"high apgar score" 2"low apgar score"
drop apgar
recode score5 (min/7=2) (8/max=1), gen (apgar) label(apgarlabel)
label variable apgar "High Apgar score at 5"
tab apgar
***************************
tab amnio_s
encode amnio_s, gen(amnio)
tab amnio

tab feed_s
encode feed_s, gen(feed1)
recode feed1 (1=1) (2=2) (3 4=3), gen (feed)
label define feedlabel 1"Breastmilk only" 2"Formula" 3"Mixed" 4"Other"
drop feed
recode feed1 (1=1) (2=2) (3 4=3), gen (feed) label(feedlabel)
tab feed

tab delivtype_s
tab delivtype_s
encode delivtype_s, gen(delivtype)
label define delivtypelabel 1 "SVD" 2 "Cesarean" 3 "Instrumental/forceps/vacuum"
drop delivtype
encode delivtype_s, gen(delivtype) label(delivtypelabel)
tab delivtype

tab initiation_s
encode initiation_s, gen(initiation)
label define initiationlabel 1 "Within one hour" 2 "One-six hours" 3 "More than six hours"
drop initiation
encode initiation_s, gen(initiation) label(initiationlabel)
tab initiation

tab anc_s
encode anc_s, gen(anc)
label define anclabel 1 "Zero" 2 "One" 3 "Two" 4"Three" 5"Four or more"
drop anc
encode anc_s, gen(anc) label(anclabel)
tab anc

tab uti_s
encode uti_s, gen(uti)
tab uti

tab immunize_s
encode immunize_s, gen(tt_immunize)
label define tt_immunizelabel 0 No 1 Yes
drop tt_immunize
encode immunize_s, gen(tt_immunize) label(tt_immunizelabel)
tab tt_immunize

tab healtheduc_s
encode healtheduc_s, gen(healtheduc)
label define healtheduclabel 0 No 1 Yes
drop healtheduc
encode healtheduc_s, gen(healtheduc) label(healtheduclabel)
tab healtheduc

tab source_s
encode source_s, gen(source)
label define healthsourcelabel 1 "Health worker" 2 "Traditional Birth Attendant" 3 "Family member" 4 "Other"
drop source
encode source_s, gen(source) label(healthsourcelabel)
tab source

tab prom_s
encode prom_s, gen(prom)
tab prom

tab complic_s
encode complic_s, gen(complic)
tab complic

******generating pregnancy related complication from uti, prom, complic and amnio***
generate score_pregcomp = uti+prom+complic+amnio
recode score_pregcomp (min/4=0) (5/max=1), gen (pregcomp)
label define pregcomplabel 0 "No pregnancy-related complication" 1 "Pregnancy-related complication"
drop pregcomp
recode score_pregcomp (min/4=0) (5/max=1), gen(pregcomp) label(pregcomplabel)
label variable pregcomp "Pregnancy-related complications"
tab pregcomp
********GENERATING UMBILICAL CORD HYGIENE******
generate byte hyg_score = substance+cordexp+handwash+washuse
tab hyg_score
recode hyg_score (min/4 = 1) (5/max = 0), gen (improper_hyg)
label define hyg_scorelabel 1 "poor hygiene" 0 "good hygiene"
drop improper_hyg
recode hyg_score (min/4 = 1) (5/max = 0), gen(improper_hyg) label(hyg_scorelabel)
label variable improper_hyg "Improper Umbilical cord hygiene"
tab improper_hyg
logistic sepsis improper_hyg
***dropping extra variables******
drop participant_s
drop neonsex_s
drop marital_s
drop educ_s
drop religion_s
drop parity_s
drop substance_s
drop cordexp_s
drop handwash_s
drop washing_s
drop rooming_s
drop bathing_s
drop cry_s
drop resusc_s
drop line_s
drop amnio_s
drop feed_s
drop delivtype_s
drop initiation_s
drop anc_s
drop uti_s
drop immunize_s
drop healtheduc_s
drop source_s
drop prom_s
drop complic_s
drop cordexp
drop handwash
drop washuse
drop rooming
drop bathing
drop cry
drop resusc
drop line
drop score_invasive
drop amnio
drop uti
drop prom
drop complic
******DESCRIPTIVE STATISTICS**************
******categorical variables*****
tab sepsis 
tab neonsex
tab marital
tab educ
tab religion
tab substance
tab place
tab feed
tab delivtype
tab initiation
tab anc
tab tt_immunize
tab healtheduc
tab pregcomp
tab apgar
tab source
tab children
tab exactcomp
tab improper_hyg
tab invasive
tab sepsis neonsex, row
tab sepsis marital1, row
tab sepsis marital, row
tab sepsis educ, row
tab sepsis religion, row
tab sepsis religions, row
tab sepsis substance, row
tab sepsis deliveryplace, row
tab sepsis feed, row
tab sepsis delivtype, row
tab sepsis initiation, row
tab sepsis anc, row
tab sepsis tt_immunize, row
tab sepsis healtheduc, row
tab sepsis source, row
tab sepsis pregcomp, row
tab sepsis apgar, row
tab sepsis improper_hyg, row
tab sepsis invasive, row
******continuous variables*****
summ children, detail
bysort sepsis: summ children, detail
mean children if sepsis==1
mean children if sepsis==0
summ neonage, detail
ci neonage
bysort sepsis: summ neonage, detail
list matage if matage==99
replace matage=. if matage==99
summ matage, detail
bysort sepsis: summ matage, detail
mean matage if sepsis==1
mean matage if sepsis==0
****UNIVARIABLE ANALYSIS***********
****exposure and outcome association*****
logistic sepsis improper_hyg //significant p=0.000 proceed to test exposure/exposure association
logistic sepsis neonsex //p=0.1472
logistic sepsis ib2.marital //significant p=0.0498 proceed to test exposure/exposure association
logistic sepsis ib3.educ //p=0.1869 
logistic sepsis i.religion //p=0.1814
logistic sepsis ib2.deliveryplace //p=0.2508
logistic sepsis invasive //significant p=0.0073 proceed to test exposure/exposure association
logistic sepsis pregcomp //significant p=0.0045 proceed to test exposure/exposure association
logistic sepsis i.feed //significant p=0.000 proceed to test exposure/exposure association
logistic sepsis i.initiation //significant p=0.0063 proceed to test exposure/exposure association
logistic sepsis i.anc //p=0.5248
logistic sepsis tt_immunize //p=0.4155
logistic sepsis healtheduc //p=0.0855
logistic sepsis apgar //significant p=0.0009 proceed to test exposure/exposure association
logistic sepsis c.children //p=0.1489
logistic sepsis neonage //significant p=0.000 proceed to test exposure/exposure association
logistic sepsis matage //p=0.1591

****exposure exposure association******
logistic improper_hyg ib2.marital //significant p=0.0465 proceed to multivariable analysis
logistic improper_hyg invasive //significant p=0.0333 proceed to multivariable analysis
logistic improper_hyg pregcomp //significant p=0.0462 proceed to multivariable analysis
logistic improper_hyg i.feed //significant p=0.0001 proceed to multivariable analysis
logistic improper_hyg i.initiation //p=0.6244
logistic improper_hyg apgar //significant p=0.0012 proceed to multivariable analysis
logistic improper_hyg neonage //significant p=0.0013 proceed to multivariable analysis

*******MULTIVARIABLE ANALYSIS********
****FULL MODEL*****
logistic sepsis improper_hyg ib2.marital invasive pregcomp i.feed apgar neonage
testparm i.marital
testparm i.feed
****backward step elimination testing confounding*************
logit sepsis improper_hyg marital invasive pregcomp feed apgar neonage
*****testing marital confounding****
logit sepsis improper_hyg invasive pregcomp feed apgar neonage
di abs(((2.396202)-(2.390882))/(2.396202)*100) //0.22% change when marital is dropped
******testing invasive confounding******
logit sepsis improper_hyg invasive pregcomp feed apgar neonage 
logit sepsis improper_hyg pregcomp feed apgar neonage
di abs(((2.385481)-(2.396202))/(2.385481)*100) //0.45% change when invasive is dropped 
******testing apgar confounding******
logit sepsis improper_hyg pregcomp feed apgar neonage
logit sepsis improper_hyg pregcomp feed neonage
di abs(((2.440821)-(2.385481))/(2.440821)*100) //2.27% change when apgar is dropped
******testing pregcomp confounding******
logit sepsis improper_hyg pregcomp feed neonage
logit sepsis improper_hyg feed neonage
di abs(((2.467856)-(2.440821))/(2.467856)*100) //1.1% change when pregcomp is dropped
******testing feed confounding******
logit sepsis improper_hyg feed neonage
logit sepsis improper_hyg neonage
di abs(((2.604041)-(2.467856))/(2.604041)*100) //5.23% change when feed is dropped
******testing neonage confounding******
logit sepsis improper_hyg neonage
logit sepsis improper_hyg
di abs(((2.583583)-(2.604041))/(2.583583)*100) //0.79% change when neonage is dropped

******ATTRIBUTABLE FRACTION= OR-1/OR********
logistic sepsis improper_hyg

di ((13.24451)-(1))/(13.24451) //0.92449702%

di abs(((13.24451)-(1))/(13.24451)*100) //92.45%
***POPULATION ATTRIBUTABLE FRACTION****
di (75/104)*(exp(_b[improper_hyg]) - 1)/exp(_b[improper_hyg])*100 //PAF of 66.67046%
 

log close 


